// Internal action code for project skygarden

package math;

import env.GardenModel;
import jason.asSemantics.*;
import jason.asSyntax.*;

@SuppressWarnings("serial")
public class get_Ag_At extends DefaultInternalAction {

	GardenModel model = GardenModel.get();
    @Override
    public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception {
    	int x = (int)((NumberTerm)args[0]).solve();
    	int y = (int)((NumberTerm)args[1]).solve();
    	
    	if(!model.hasObject(GardenModel.RED, x, y)) {
    		return false;
    	}
    	int agId = model.getAgAtPos(x, y);
    	String Ag = "v" + (agId - 2);
    	un.unifies(args[2], new Atom(Ag));
    	return true;
    }
}
